/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
  .name = "defaultTask",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for motor */
osThreadId_t motorHandle;
const osThreadAttr_t motor_attributes = {
  .name = "motor",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityLow,
};
/* Definitions for gyro */
osThreadId_t gyroHandle;
const osThreadAttr_t gyro_attributes = {
  .name = "gyro",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityLow,
};
/* Definitions for pt505 */
osThreadId_t pt505Handle;
const osThreadAttr_t pt505_attributes = {
  .name = "pt505",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityLow,
};
/* Definitions for commander */
osThreadId_t commanderHandle;
const osThreadAttr_t commander_attributes = {
  .name = "commander",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityLow,
};
/* Definitions for view */
osThreadId_t viewHandle;
const osThreadAttr_t view_attributes = {
  .name = "view",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityLow,
};
/* Definitions for RC_Task */
osThreadId_t RC_TaskHandle;
const osThreadAttr_t RC_Task_attributes = {
  .name = "RC_Task",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityLow,
};
/* Definitions for GyroSemBinary */
osSemaphoreId_t GyroSemBinaryHandle;
const osSemaphoreAttr_t GyroSemBinary_attributes = {
  .name = "GyroSemBinary"
};
/* Definitions for Pt505SemBinary */
osSemaphoreId_t Pt505SemBinaryHandle;
const osSemaphoreAttr_t Pt505SemBinary_attributes = {
  .name = "Pt505SemBinary"
};
/* Definitions for ViewSemBinary */
osSemaphoreId_t ViewSemBinaryHandle;
const osSemaphoreAttr_t ViewSemBinary_attributes = {
  .name = "ViewSemBinary"
};
/* Definitions for RcSemBinary */
osSemaphoreId_t RcSemBinaryHandle;
const osSemaphoreAttr_t RcSemBinary_attributes = {
  .name = "RcSemBinary"
};

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

void StartDefaultTask(void *argument);
void motor_task(void *argument);
void gyro_task(void *argument);
void pt505_task(void *argument);
void commander_task(void *argument);
void view_task(void *argument);
void RcData_Task(void *argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* Create the semaphores(s) */
  /* creation of GyroSemBinary */
  GyroSemBinaryHandle = osSemaphoreNew(1, 1, &GyroSemBinary_attributes);

  /* creation of Pt505SemBinary */
  Pt505SemBinaryHandle = osSemaphoreNew(1, 1, &Pt505SemBinary_attributes);

  /* creation of ViewSemBinary */
  ViewSemBinaryHandle = osSemaphoreNew(1, 1, &ViewSemBinary_attributes);

  /* creation of RcSemBinary */
  RcSemBinaryHandle = osSemaphoreNew(1, 1, &RcSemBinary_attributes);

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
  /* creation of defaultTask */
  defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);

  /* creation of motor */
  motorHandle = osThreadNew(motor_task, NULL, &motor_attributes);

  /* creation of gyro */
  gyroHandle = osThreadNew(gyro_task, NULL, &gyro_attributes);

  /* creation of pt505 */
  pt505Handle = osThreadNew(pt505_task, NULL, &pt505_attributes);

  /* creation of commander */
  commanderHandle = osThreadNew(commander_task, NULL, &commander_attributes);

  /* creation of view */
  viewHandle = osThreadNew(view_task, NULL, &view_attributes);

  /* creation of RC_Task */
  RC_TaskHandle = osThreadNew(RcData_Task, NULL, &RC_Task_attributes);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */

  /* USER CODE BEGIN RTOS_EVENTS */
  /* add events, ... */
  /* USER CODE END RTOS_EVENTS */

}

/* USER CODE BEGIN Header_StartDefaultTask */
/**
  * @brief  Function implementing the defaultTask thread.
  * @param  argument: Not used
  * @retval None
  */
/* USER CODE END Header_StartDefaultTask */
__weak void StartDefaultTask(void *argument)
{
  /* USER CODE BEGIN StartDefaultTask */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END StartDefaultTask */
}

/* USER CODE BEGIN Header_motor_task */
/**
* @brief Function implementing the motor thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_motor_task */
__weak void motor_task(void *argument)
{
  /* USER CODE BEGIN motor_task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END motor_task */
}

/* USER CODE BEGIN Header_gyro_task */
/**
* @brief Function implementing the gyro thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_gyro_task */
__weak void gyro_task(void *argument)
{
  /* USER CODE BEGIN gyro_task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END gyro_task */
}

/* USER CODE BEGIN Header_pt505_task */
/**
* @brief Function implementing the pt505 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_pt505_task */
__weak void pt505_task(void *argument)
{
  /* USER CODE BEGIN pt505_task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END pt505_task */
}

/* USER CODE BEGIN Header_commander_task */
/**
* @brief Function implementing the commander thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_commander_task */
__weak void commander_task(void *argument)
{
  /* USER CODE BEGIN commander_task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END commander_task */
}

/* USER CODE BEGIN Header_view_task */
/**
* @brief Function implementing the view thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_view_task */
__weak void view_task(void *argument)
{
  /* USER CODE BEGIN view_task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END view_task */
}

/* USER CODE BEGIN Header_RcData_Task */
/**
* @brief Function implementing the RC_Task thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_RcData_Task */
__weak void RcData_Task(void *argument)
{
  /* USER CODE BEGIN RcData_Task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END RcData_Task */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

/* USER CODE END Application */

